\chapter{Sequencing}

In this part, we give details about the steps needed to perform some important actions.

\section{Starting a process}
Here is the sequence of steps needed:
\begin{enumerate}
	\item create a new process with a PCB
	\item load the program code into that process
	\item set the PC to the entry point of this program and start executing
\end{enumerate}

\section{Scheduling processes}
The sequence of steps is:
\begin{enumerate}
	\item select the highest priority process in the ready queue
	\item if this process has a higher priority than the running process (if any), continue. Otherwise, do nothing
	\item if there are several processes with the highest priority, allocate a time quantum to the chosen one
	\item the dispatcher allocates the CPU to that process (context switch is done here), either for a give time or until it terminates (or until a process with higher priority arrives), preempting the running process if any
\end{enumerate}

\section{Printing to the screen}
Assuming we got a character to print to the screen, the steps are:
\begin{enumerate}
	\item set the data in the data register
	\item activate the interrupts in the control register
	\item wait until the I/O is done
\end{enumerate}

\section{Starting the operating system}
The sequence of steps is:
\begin{enumerate}
	\item set some parameters in the bootstrap program (such as the stack)
	\item jump to some predefined location in the kernel
	\item initialize kernel data structures
	\item start some user programs (a shell, for example)
\end{enumerate}

\section{Sending a message}
Here are the steps needed:
\begin{enumerate}
	\item get the identity of the receiving process, the message type and the data from the sender
	\item put the message in the receiver queue or report an error if the queue is full
\end{enumerate}

\section{Receiving a message}
The steps are:
\begin{enumerate}
	\item get the type of message the process is waiting for (through a parameter to the system call, likely)
	\item wait until a correct message arrives
	\item get the message and parse the content to get the data
	\item return the data to the receiver
\end{enumerate}

\section{Registering as a supervisor}
Here is the sequence of steps:
\begin{enumerate}
	\item give a set containing the identities of the processes to supervise. 
	\item register the process in the kernel as a supervisor of the given processes
\end{enumerate}

\section{Terminating a process}
The sequence of steps is:
\begin{enumerate}
	\item the process signals the OS of its termination and returns a code allowing a supervisor to differentiate between correct and incorrect termination.
	\item all resources allocated to this process are taken back
	\item if the process is supervised, the returned code is transmitted to him
	\item the process' PCB is deallocated
\end{enumerate}
